var app = new Vue({
    el: '#app',
    data: {
        form: {
            keywords: '',
            current_page: 1,
            total: 0,
            page_size: 15
        },
        table: {
            list: []
        },
        pageInfo: {
            title: '栏目'
        },
        dialog: {
            isShow: false,
            title: '',
            disabled: false
        },
        communityDetail: {}
    },
    mounted:function(){
        this.getCateList()
    },
    methods: {
        roomAdd:function(id) {
            window.location.href = '/building/detail?id=' + this.community.id;
        },
        getCateList: function() {
            var _this = this;
            // 获取栏目
            $.ajax({
                url: '/ssq/getList',
                type: 'get',
                data: _this.form,
                dataType: 'json',
                success: function(res) {
                    console.log(res)
                    if (res.status === 0) {
                        _this.table.list = res.data.data;
                        _this.form.current_page = res.data.current_page;
                        _this.form.total = res.data.total;
                    } else {
                        _this.$message.error(res.message)
                    }
                }
            })
        },
        addCate: function() {
            var _this = this;
            _this.$prompt('请输入栏目名称', '栏目', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                inputValue:'',
            }).then(({value}) => {
                if (value != null && value !== "") {
                    console.log(value)
                    // 新增栏目
                    $.ajax({
                        url: '/ssq/save',
                        type: 'post',
                        data: {name: value},
                        dataType: 'json',
                        success: function(res) {
                            if (res.status === 0) {
                                _this.$message.success(res.message)
                                _this.getCateList()
                            } else {
                                _this.$message.error(res.message)
                            }
                        }
                    })
                } else {
                    _this.$message({
                        type: 'warning',
                        message: '未输入任何信息'
                    })
                }
            }).catch(() => {

            })
        },
        editCate: function(id, cate) {
            var _this = this;
            _this.$prompt('请输入栏目名称', '栏目', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                inputValue:cate,
            }).then(({value}) => {
                if (value != null && value !== "") {
                    console.log(value)
                    // 修改栏目
                    $.ajax({
                        url: '/ssq/save',
                        type: 'post',
                        data: {name: value, id: id},
                        dataType: 'json',
                        success: function(res) {
                            if (res.status === 0) {
                                _this.$message.success(res.message)
                                _this.getCateList()
                            } else {
                                _this.$message.error(res.message)
                            }
                        }
                    })
                } else {
                    _this.$message({
                        type: 'warning',
                        message: '未输入任何信息'
                    })
                }
            }).catch(() => {

            })
        },
        deleteCate: function(id) {
            var _this = this;
            _this.$confirm('是否删除?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                // 处理删除逻辑
                $.ajax({
                    url: '/ssq/del',
                    type: 'post',
                    data: {id: id},
                    dataType: 'json',
                    success: function(res) {
                        if (res.status === 0) {
                            _this.$message.success(res.message)
                            _this.getCateList()
                        } else {
                            _this.$message.error(res.message)
                        }
                    }
                })
            }).catch(() => {

            });

        }

    }
});
$(document).keyup(function(e){
    var key = e.which;
    if(key==13){
        app.getCommunityList();
        return false;
    }
});
